/**
 * Created by sun on 2016/8/4.
 */
define(function (require) {
    var app = require('/../js/app');
    require('ui-table');

    require('ueditor.all.min');
    require('ueditor.config');
    require('angular-ueditor');


    app.useModule("ui.table");

    app.useModule("ng.ueditor");

    var datepicker = require('datepicker');
    app.controller('listCtrl', ['$scope','$http' ,function ($scope, $http) {
        $scope.orderParams = {
            url: "/admin/sysad/getList"
        };
        datepicker($scope);

        //创建
        $scope.addOrderModal=function(){
            $scope.orderModal = !$scope.orderModal ;
        };

        //全局查询
        $scope.search = function() {
            $scope.ctrlScope.trend.beginDate=$filter('date')($scope.ctrlScope.trend.beginDate,'yyyy-MM-dd');
            $scope.ctrlScope.trend.endDate=$filter('date')($scope.ctrlScope.trend.endDate,'yyyy-MM-dd');
            //表格查询参数设置
            $scope.orderParams.ajaxParam=$scope.ctrlScope.trend;
            console.info( $scope.orderParams.ajaxParam);
            //表格刷新
            $scope.orderParams.reload();
        };

        //全局查询重置
        $scope.reset=function(){

            $scope.search();
        };

        //文章创建
        $scope.adoptAdd = function(){
            $http({
                method: 'POST',
                url: "",
                data: {

                }
            }).success(function(data) {
                console.info(data);
                alert("创建成功！");
                $scope.addModal = !$scope.addModal;
                $scope.orderParams.reload();
            }).error(function(data) {
            });
        };

        //上传图片
        $scope.getFile = function () {
            fileReader.readAsDataUrl($scope.file, $scope)
                .then(function(result) {
                    $scope.imageSrc = result;
                });
            // 组装表单数据
            var postData = {
                vacationType: $scope.leave.type,
                reason: $scope.leave.reason,
                familyRelation: +$scope.leave.type == 7 ? $scope.leave.relation : "",
                startTime: startTime,
                endTime: endTime,
                fileName: $scope.imageSrc,
                workDelivers: workDelivers,
                ccmailNickNames: sendPersons,
                realDays: +$scope.leave.type == 8 ? $scope.leave.timeLong : ""
            };
            var promise = postMultipart('/maldives/leave/save', postData);
            function postMultipart(url, data) {
                var fd = new FormData();
                angular.forEach(data, function(val, key) {
                    fd.append(key, val);
                });
                var args = {
                    method: 'POST',
                    url: url,
                    data: fd,
                    headers: {'Content-Type': undefined},
                    transformRequest: angular.identity
                };
                return $http(args);
            }
        };


    }]);


});